package com.trace.basic;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by denglw on 2020/1/13.<br/>
 * Desc: 线程优先级
 */
@SuppressWarnings({"AlibabaUndefineMagicConstant", "AlibabaThreadPoolCreation"})
public class Priority {

    public static void main(String[] args) {
        List<Runnable> runnables = new ArrayList<>(10);
        for (int i = 0; i < 10; i++) {
            String name = "thread" + (i + 1);
            Thread thread = new Thread(() -> System.out.println(name + "执行"), name);
            thread.setPriority(i + 1);
            runnables.add(thread);
        }
        ExecutorService pool = Executors.newFixedThreadPool(5);
        runnables.forEach(pool::execute);
        pool.shutdown();
    }
}
